/*
 * 使用示例:
 * app.use(session(options));
 * 
 * options支持的参数:
 * 1、https://github.com/Secbone/koa-session2
 * 2、如需使用redis，请设置options.redis，支持的参数:
 *    2-1 host 主机地址
 *    2-2 port 端口
 *    2-3 password 授权密码
 *    2-4 keyPrefix redis key前缀
 */
'use strict';

const session = require('koa-session2');
const Redis = require('./redis');

exports = module.exports = (options) => {
  if (options.redis) {
    delete options.store;
    let scfg = Object.assign({
      store: new Redis(options.redis, options.maxAge)
    }, options);
    delete scfg.redis;
    return session(scfg);
  } else {
    return session(options);
  }
};